import DList from "@/components/dlist";
export default {
  data() {
    return {
      activeName: 1,
      popupShow: false,
      detailList: [],
      amountSummary: [],
      loading: false,
      finished: false,
      page: 1,
      memberData: {}
    }
  },
  // watch: {
  //   popupShow(newVal, oldVal) {
  //     if (newVal) {
  //       //滑动到底部触发事件
  //       this.$nextTick(() => {
  //         let unpackingGoods = document.getElementsByClassName("van-popup");
  //         unpackingGoods[0].onscroll = () => {
  //           let scrollHeight = unpackingGoods[0].scrollHeight;
  //           let clientHeight = unpackingGoods[0].clientHeight;
  //           let scrollTop = Math.round(unpackingGoods[0].scrollTop);
  //           if (scrollHeight == clientHeight + scrollTop) {
  //             this.getData();
  //           }
  //         };
  //       });
  //     }
  //   }
  // },
  activated(){
    this.popupShow = false;
    this.getTopData();
    this.getAmountLog();
    this.getAmountSummary()
  },
  methods: {
    toPoint(item) {
      this.$router.push(this.fun.getUrl('consumption_dividend_toPoint', { pool_id: item.pool_id}))
    },
    async getAmountSummary() {
      let { data, result, msg } = await $http.post("plugin.consume-commission.frontend.index.amountSummary", {});
      if (result) {
        this.amountSummary = data;
      } else {
        this.$toast(msg);
      }
    },
    async getTopData() {
      let { data, result, msg } = await $http.post("plugin.consume-commission.frontend.index.index", {});
      if (result) {
        this.memberData = data;
      } else {
        this.$toast(msg);
      }
    },
    async getAmountLog(key) {
      if (this.loading === true || this.finished === true) {
        return;
      }
      this.loading = true;
      let url = this.activeName == 1 ? "plugin.consume-commission.frontend.index.amountLog" : "plugin.consume-commission.frontend.index.rewardLog"
      let { data, result, msg } = await $http.post(url, { page: this.page });
      if (result) {
        if(key == 'more'){
          this.detailList.push(...data.data);
          if (data.data.length === 0 || data.data.length < data.per_page || data.current_page === data.last_page) {
            this.finished = true;
          }
          this.page++;
          this.isShowDirect = true;
          this.loading = false;
        }else{
          this.detailList = data.data;
          this.loading = false;
          if (data.data.length === 0 || data.data.length < data.per_page || data.current_page === data.last_page) {
            this.finished = true;
          }
        }
      } else {
        this.$toast(msg);
      }
    },
    onLoad() {
      this.getAmountLog('more');
    },
    filterAmount(val) {
      return (val + '').indexOf("-") == -1 ? true : false
    },
    clickEvent() {
      this.detailList = [];
      this.loading = false;
      this.finished = false;
      this.page = 1;
      this.getAmountLog();
    }
  },
  components: { DList }
};
